/*
 *  $Id: Rect.cs 1232 2010-12-07 13:16:37Z thenn.erannor $
 *  This file is a part of Ragima CCG.
 *  (C) 2008-2010 Ragima development group.
 *
 *  Licensed under the terms of the GNU GPL License version 2.
 *
 */

using AgateLib.DisplayLib;
using AgateLib.Geometry;

using Nereal.Serialization;

namespace Ragima.UI {
    /// <summary>
    /// Простой закрашенный прямоугольник.
    /// </summary>
    [TypeId("rect")]
    public class Rect : Widget {
        private const bool DefaultBorder = false;
        private static readonly Color DefaultBorderColor = Color.Black;
        private const bool DefaultFill = false;
        private static readonly Color DefaultFillColor = Color.Black;

        private bool _border, _fill;

        public Rect() {
            _border = DefaultBorder;
            _fill = DefaultFill;
        }

        /// <summary>
        /// Рисовать ли рамку у прямоугольника.
        /// </summary>
        [XmlName("border"), DefaultValue(DefaultBorder)]
        public bool Border {
            get { return _border; }
            set { _border = value; }
        }

        /// <summary>
        /// Закрашивать ли прямоугольник.
        /// </summary>
        [XmlName("fill"), DefaultValue(DefaultFill)]
        public bool Fill {
            get { return _fill; }
            set { _fill = value; }
        }

        /// <summary>
        /// Рисует прямоугольник.
        /// </summary>
        public override void Draw() {
            var bounds = AbsoluteBounds;
            if (_fill)
                Display.FillRect(bounds, BackColor ?? DefaultFillColor);
            if (_border)
                Display.DrawRect(bounds, MainColor ?? DefaultBorderColor);
        }
    }
}
